package org.cbg.panel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import org.cbg.until.TraslationTableZhaohuanshouUntil;
import org.come.entity.RoleSummoning;



/**
 * 我要卖 寄售商品召唤兽分类 面板
 * 
 * @author Administrator
 * 
 */
public class TraslationWantSendJishoushangpinFenleiZhaohuanshouJpanel extends JPanel {

    private JScrollPane jScrollPane;
    private JPanel jPanel;
    private List<TraslationWantSendJishoushangpinFenleiZhaohuanshouModelJpanel> lists;

    public TraslationWantSendJishoushangpinFenleiZhaohuanshouJpanel() {
        // TODO Auto-generated constructor stub

        this.setPreferredSize(new Dimension(385, 340));
        this.setOpaque(false);
        this.setLayout(null);


        jScrollPane = new JScrollPane();
        jScrollPane.setBounds(0, 34, 380, 200);
        jPanel = TraslationTableZhaohuanshouUntil.TableModel(jScrollPane);
        jScrollPane.getVerticalScrollBar().setUnitIncrement(50);
        this.add(jScrollPane);
    }

    /** 重置图片 true添加 */
    public void chang(RoleSummoning pet, boolean is) {
        if (lists == null) {
            lists = new ArrayList<>();
        }
        for (int i = 0; i < lists.size(); i++) {
            TraslationWantSendJishoushangpinFenleiZhaohuanshouModelJpanel modelJpanel = lists.get(i);
            if (modelJpanel.getRgid().compareTo(pet.getSid()) == 0) {
                if (is) {
                    modelJpanel.chang(pet);
                    return;
                } else {
                    lists.remove(modelJpanel);
                    jPanel.remove(modelJpanel);
                    tz();
                    return;
                }
            }
        }
        if (is) {
            TraslationWantSendJishoushangpinFenleiZhaohuanshouModelJpanel modelJpanel = new TraslationWantSendJishoushangpinFenleiZhaohuanshouModelJpanel(
                    pet);
            lists.add(modelJpanel);
            jPanel.add(modelJpanel);
            tz();
            return;
        }
    }

    /** 调整窗体位置 */
    public void tz() {
        for (int i = 0; i < lists.size(); i++) {
            TraslationWantSendJishoushangpinFenleiZhaohuanshouModelJpanel modelJpanel = lists.get(i);
            modelJpanel.setBounds(0, i * 50, 385, 50);
        }
        jPanel.setPreferredSize(new Dimension(760, 62 * lists.size()));
        jScrollPane.getViewport().setViewSize(jPanel.getPreferredSize());
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = new ImageIcon("inkImg/number/b4/zgsxsk.png");
        }
        g.drawImage(icon.getImage(), 0, 0, 385, 240, this);
    }

}
